//
//  QWHttpEngineConfig.m
//  WJHttpEngineAPI-example
//
//  Created by Yunhai.Wu on 15/12/25.
//  Copyright © 2015年 WJ. All rights reserved.
//

#import "QWHttpEngineConfig.h"
#import "IQWHttpEngine.h"
#import "IQWHttpFilter.h"

@interface QWHttpEngineConfig ()
@property (nonatomic, strong) NSMutableArray *fs;
@end

@implementation QWHttpEngineConfig

DEF_SINGLETON_INIT(QWHttpEngineConfig)

-(void) singleInit {
    _defaultTimeoutDuration = 60;
    _defaultNetworkActivityEnabled = YES;
    _fs = [[NSMutableArray alloc] init];
}

-(void) setTimeoutDuration:(int) timeoutDuration {
    if (timeoutDuration > 0) {
        _defaultTimeoutDuration = timeoutDuration;
    }
}

-(void) setEngine:(Class) engineClazz {
    if (engineClazz) {
        if (![engineClazz conformsToProtocol:@protocol(IQWHttpEngine)]) {
            NSString *reason = [NSString stringWithFormat:@"%@ 没有实现协议 IQWHttpEngine",NSStringFromClass(engineClazz)];
            @throw [NSException exceptionWithName:@"WJHttpEngineException" reason:reason userInfo:nil];
        }
    }
    _defaultEngine = engineClazz;
}

-(void) setNetworkActivityEnabled:(BOOL) enabled {
    _defaultNetworkActivityEnabled = enabled;
}

-(void) addFilter:(Class) filterClazz {
    if (filterClazz) {
        if ([filterClazz conformsToProtocol:@protocol(IQWHttpFilter)]) {
            [_fs addObject:filterClazz];
        } else {
            NSString *reason = [NSString stringWithFormat:@"%@ 没有实现过滤器协议 IQWHttpFilter",NSStringFromClass(filterClazz)];
            @throw [NSException exceptionWithName:@"WJHttpEngineException" reason:reason userInfo:nil];
        }
    }
}

@end
